package com.weilai.service.serviceImpl;

import com.weilai.controller.exceptionHandler.BusinessException;
import com.weilai.controller.exceptionHandler.Code;
import com.weilai.dao.DraftDao;
import com.weilai.domain.Drafts;
import com.weilai.service.DraftsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DraftsServiceImpl implements DraftsService {
    @Autowired
    private DraftDao draftDao;

    public Drafts selectByPostId(int postId){
        Drafts drafts = draftDao.selectByPostId(postId);
        return drafts;
    }

    public void addDrafts(Drafts drafts){
        draftDao.addDrafts(drafts);
    }

    public void updateDrafts(Drafts drafts){
        draftDao.updateDrafts(drafts);
    }


    public List<Drafts> selectByUserId(int userId){
        List<Drafts> drafts = draftDao.selectByUserId(userId);
        return drafts;
    }

    // 按 userid 删除草稿
    @Override
    public void deleteUserById(int userId){
        try {
            draftDao.deleteUserById(userId);
        } catch (Exception e) {
            throw new BusinessException(Code.SYSTEM_DB_ERROR, "按id删除用户信息时数据库出错");
        }
    }
}
